package com.chinasofti.suse.ssm.ssmintegrated.service.impl;

import com.chinasofti.suse.ssm.ssmintegrated.dao.UserMapper;
import com.chinasofti.suse.ssm.ssmintegrated.model.User;
import com.chinasofti.suse.ssm.ssmintegrated.service.UserService;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        //验证
        if (Strings.isNullOrEmpty(username)
                || Strings.isNullOrEmpty(password)
                || username.length() < 6
                || password.length() < 6)
        {
            throw new IllegalArgumentException("参数异常");
        }
        //查询
        User user = userMapper.findUserByUsername(username);
        if(user==null||!password.equals(user.getPassword())){
            throw new RuntimeException("用户不存在或者密码不正确");
        }

        return user;

    }
}
